package vtt.android.dapanhc.database;

import vtt.android.dapanhc.BaseApplication;
import vtt.android.library.utils.VttLog;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class MySQLiteOpenHelper extends SQLiteOpenHelper {

	private static final String TAG = "MySQLiteOpenHelper";
	// Database Version
	private static final int DATABASE_VERSION = 1;
	// Database Name
	private static final String DATABASE_NAME = "vtt_dapanhc.db";
	private Context mContext;
	VttLog log = new VttLog(TAG, BaseApplication.isDebuggable);

	public MySQLiteOpenHelper(Context context) {
		super(context, DATABASE_NAME, null, DATABASE_VERSION);
		this.mContext = context;
	}

	// Creating Tables
	@Override
	public void onCreate(SQLiteDatabase db) {
		createQuestionTable(db);
		createChallengeDateTable(db);
	}

	// Upgrading database
	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		// Drop older table if existed
	}

	private void createQuestionTable(SQLiteDatabase db) {
		String sql = " CREATE TABLE " + AnswerDAO.TABLE_QUESTIONNAIRE + " ( " 
				+ " sid TEXT PRIMARY KEY, " 
				+ " suggestion TEXT, " 
				+ " en TEXT, "
				+ " vn TEXT, "
				+ " sound_url TEXT"
				+ ");";
		db.execSQL(sql);
	}
	
	private void createChallengeDateTable(SQLiteDatabase db) {
		String sql = " CREATE TABLE " + AnswerDAO.TABLE_CHALLENGE_DATE + " ( " 
				+ " date TEXT, " 
				+ " sid TEXT, " 
				+ " PRIMARY KEY ( date, sid )"
				+ " );";
		db.execSQL(sql);
	}
}
